package com.demo.modules.redis;


import com.demo.common.constant.RedisKeysConstant;
import com.demo.common.utils.RedisUtils;
import com.demo.modules.sys.entity.SysUserTokenEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 系统配置Redis
 */
@Component
public class SysTokenRedis {

    @Autowired
    private RedisUtils redisUtils;

    public void saveOrUpdate(SysUserTokenEntity sysUserTokenEntity) {
        if (sysUserTokenEntity == null) {
            return;
        }
        String key = RedisKeysConstant.getSysTokenKey(sysUserTokenEntity.getToken());
        redisUtils.set(key, sysUserTokenEntity);
    }

    public void delete(String sysUserToken) {
        String key = RedisKeysConstant.getSysTokenKey(sysUserToken);
        redisUtils.delete(key);
    }

    public SysUserTokenEntity get(String sysUserToken) {
        String key = RedisKeysConstant.getSysTokenKey(sysUserToken);
        return redisUtils.get(key, SysUserTokenEntity.class);
    }
}
